maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=buildkit
pkgver=0.16.0
pkgrel=0
pkgdesc="Concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit"
url="https://github.com/moby/buildkit"
arch="all"
license="Apache-2.0"
depends="containerd"
makedepends="go"
subpackages="$pkgname-openrc $pkgname-doc buildctl"
source="$pkgname-$pkgver.tar.gz::https://github.com/moby/buildkit/archive/refs/tags/v$pkgver.tar.gz
	buildkitd.initd
	buildkitd.confd
	"
options="!check" # needs to mount various things as root

# secfixes:
#   0.12.5-r0:
#     - CVE-2024-23650
#     - CVE-2024-23651
#     - CVE-2024-23652
#     - CVE-2024-23653

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	mkdir -p out
	go build -v \
		-ldflags="
		-X github.com/moby/buildkit/version.Version=v$pkgver \
		-X github.com/moby/buildkit/version.Revision=alpine \
		" \
		-o out/ \
		./cmd/...

	# The file's content is just the output of 'buildctl build --help'
	rm -r docs/reference

}

package() {
	install -Dm755 ./out/* \
		-t "$pkgdir"/usr/bin/
	install -Dm755 "$srcdir"/buildkitd.initd \
		"$pkgdir"/etc/init.d/buildkitd
	install -Dm644 "$srcdir"/buildkitd.confd \
		"$pkgdir"/etc/conf.d/buildkitd

	install -Dm644 docs/*.md -t "$pkgdir"/usr/share/doc/$pkgname/
	cp -r docs/attestations docs/dev "$pkgdir"/usr/share/doc/$pkgname/
}

buildctl() {
	pkgdesc="$pkgdesc (cli frontend)"
	amove usr/bin/buildctl
}

sha512sums="
f0be551fd21fea3cfc1a02186347a9419a6d69bcfa138922980a35a78aa15b53c45acf4f95952dae04ca6bf6e750dd41e98e13f02ca6cfd79e01f18e8f4eb9e1  buildkit-0.16.0.tar.gz
01007221e6aab7a9f9565b48d2a338b2a72508234c7874a4aeaf9fd9181a19ffebe6374560bbae0262b009643b1fb49fb51b0f8006540355ae0f42fbaad5dd59  buildkitd.initd
44efad35c5867266a84246cf49afd2c4d775a530409397c817c8026873c75686432388325cd7654d939e8bfeceeada9112f3dd814ae5d95d4470373c3aa6dc3e  buildkitd.confd
"
